package com.ruoyi.project.wx.user.controller;


import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.wx.user.domain.BindUser;
import com.ruoyi.project.wx.user.domain.FollowUser;
import com.ruoyi.project.wx.user.service.BindUserService;
import com.ruoyi.project.wx.user.service.FollowUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 用户信息
 *
 * @author wh
 */
@Controller
@RequestMapping("/wx/user")
public class BindUserController extends BaseController {

    private String prefix = "wx/user";

    @Autowired
    private BindUserService bindUserService;

    @Autowired
    private FollowUserService followUserService;

    @RequiresPermissions("wx:user:bind:view")
    @GetMapping("/bind")
    public String toBindUserList()
    {
        return prefix + "/bind/list";
    }

    @RequiresPermissions("wx:user:follow:view")
    @GetMapping("/follow")
    public String toFollowUserList()
    {
        return prefix + "/follow/list";
    }

    @RequiresPermissions("wx:user:bind:list")
    @PostMapping("/bind/list")
    @ResponseBody
    public TableDataInfo bindUserlist(BindUser bindUser) {
        startPage();
        List<BindUser> bindUserList = bindUserService.bindUserlist(bindUser);
        return getDataTable(bindUserList);
    }

    @RequiresPermissions("wx:user:follow:list")
    @PostMapping("/follow/list")
    @ResponseBody
    public TableDataInfo followUserlist(FollowUser followUser) {
        startPage();
        List<FollowUser> followUserList = followUserService.followUserlist(followUser);
        return getDataTable(followUserList);
    }

    @RequiresPermissions("wx:user:bind:remove")
    @PostMapping("/bind/remove")
    @ResponseBody
    public AjaxResult bindUserRemove(String ids)
    {
        try
        {
            return toAjax(bindUserService.delbindUserByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    @RequiresPermissions("wx:user:follow:remove")
    @PostMapping("/follow/remove")
    @ResponseBody
    public AjaxResult followUserRemove(String ids)
    {
        try
        {
            return toAjax(followUserService.delfollowUserByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }
}
